package com.vows.init.config;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

/**
 * @项目: webbit-web
 * @所属包: com.vows.init.config
 * @描述: 用来替代 Spring mvc的配置文件 
 * @authur:vows
 * @创建日期:2017年4月29日-下午5:50:27
 * 2017  PD.Sp Center . GDT Co.Ltd  -版权所有
 * 
 */
@Configuration
@ComponentScan("com.vows")
@EnableWebMvc
@ImportResource("classpath*:spring-mvc.xml")
public class WebConfig extends WebMvcConfigurerAdapter{
	//配置试图解析控制器
	@Bean
	public ViewResolver viewResolver(){
		InternalResourceViewResolver inResolver = new InternalResourceViewResolver(); 
		inResolver.setPrefix("/WEB-INF/view/");
		inResolver.setSuffix(".html");
		inResolver.setExposeContextBeansAsAttributes(true);
		return inResolver;
	}
	//配置静态资源处理.将静态资源转发到servlet容器默认的servlet上
	@Override
	public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer){
		configurer.enable();
	}
	
	//配置静态资源转发路径
	//the same in xml <mvc:resource mapping="" location="" cache-period="">
	public void addResourceHandlers(ResourceHandlerRegistry registry){
		System.out.println("resource handleriing");
		registry.addResourceHandler("classpath:/ui/adminlte/**").addResourceLocations("/ui/adminltes/").setCachePeriod(31556926);
	}
	
}
